export default {
  tree (data) {
    let map = {}
    data.forEach(function (item) {
      map[item.id] = item
    })
    let val = []
    data.forEach(function (item) {
      let parent = map[item.parent_id]
      if (parent) {
        (parent.children || (parent.children = [])).push(item)
      } else {
        val.push(item)
      }
    })
    return val
  }
}
